/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [EditMenuToolBar.java]
 * Creation Date        [11-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.notepad_V1.ui.edit;

import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

/**
 * 编辑菜单浮动工具栏
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class EditMenuToolBar extends JToolBar {

	private static final long serialVersionUID = 7947563485590691570L;

	private final ActionListener listener;

	private Icon cutIcon = null;
	private Icon copyIcon = null;
	private Icon pasteIcon = null;
	private Icon undoIcon = null;
	private Icon redoIcon = null;

	private JButton cutButton = null;
	private JButton copyButton = null;
	private JButton pasteButton = null;
	private JButton undoButton = null;
	private JButton redoButton = null;

	/**
	 * 初始化编辑浮动工具栏
	 */
	private void init() {
		cutIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/cut.gif");
		copyIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/copy.gif");
		pasteIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/paste.gif");
		undoIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/undo.gif");
		redoIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/redo.gif");

		cutButton = new JButton(cutIcon);// 剪切
		copyButton = new JButton(copyIcon); // 复制
		pasteButton = new JButton(pasteIcon);// 粘贴
		undoButton = new JButton(undoIcon);// 撤销
		redoButton = new JButton(redoIcon);// 重做

		cutButton.addActionListener(listener);
		copyButton.addActionListener(listener);
		pasteButton.addActionListener(listener);
		undoButton.addActionListener(listener);
		redoButton.addActionListener(listener);

		cutButton.setToolTipText("剪切");// 剪切
		copyButton.setToolTipText("复制"); // 复制
		pasteButton.setToolTipText("粘贴");// 粘贴
		undoButton.setToolTipText("撤销");// 撤销
		redoButton.setToolTipText("重做");// 重做

		this.add(undoButton);
		this.add(redoButton);
		this.addSeparator(); // 添加分割线
		this.add(cutButton);
		this.add(copyButton);
		this.add(pasteButton);

		/**
		 * 初始化浮动工具栏
		 */
		setFloatable(true); // 设置工具栏为可浮动
		FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, 0, 0);
		setLayout(flowLayout);
		flowLayout.setAlignOnBaseline(true);
	}

	public EditMenuToolBar(ActionListener listener) {
		this.listener = listener;
		init();
	}

	public JButton getCutButton() {
		return cutButton;
	}

	public JButton getCopyButton() {
		return copyButton;
	}

	public JButton getPasteButton() {
		return pasteButton;
	}

	public JButton getUndoButton() {
		return undoButton;
	}

	public JButton getRedoButton() {
		return redoButton;
	}

}
